package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceMonthlyAddDTO;
import org.jsola.hr.dto.SalaryBillAddDTO;
import org.jsola.hr.dto.SalaryBillUpdateDTO;
import org.jsola.hr.entity.SalaryBillDO;
import org.jsola.hr.query.SalaryBillQuery;
import org.jsola.hr.service.IAttendanceMonthlyService;
import org.jsola.hr.service.ISalaryBillService;
import org.jsola.hr.vo.SalaryBillVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class SalaryBillTestHelper extends BaseTestHelper {

    @Autowired
    private ISalaryBillService salaryBillService;

    @Autowired
    private IAttendanceMonthlyService attendanceMonthlyService;

    /**
     * 生成add测试数据
     * @return SalaryBillAddDTO
     */
    public SalaryBillAddDTO getSalaryBillAddDTO(){
        SalaryBillAddDTO salaryBillAddDTO = new SalaryBillAddDTO();
        salaryBillAddDTO.setTableId(getRandomValue("varchar",32));
        salaryBillAddDTO.setEmpInCompany(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillAddDTO.setEmpId(getRandomValue("varchar",32));
        salaryBillAddDTO.setYear(getRandomValue("varchar",32));
        salaryBillAddDTO.setMonth(getRandomValue("varchar",32));
        salaryBillAddDTO.setSalaryAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryBillAddDTO.setSalaryReal(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryBillAddDTO.setSendType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryBillAddDTO.setSendStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillAddDTO.setReadStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillAddDTO.setCheckStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillAddDTO.setWithdrawnStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillAddDTO.setSendTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        salaryBillAddDTO.setReadTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        salaryBillAddDTO.setCheckTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        salaryBillAddDTO.setWithdrawnTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        salaryBillAddDTO.setPhoneStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillAddDTO.setPhone(getRandomValue("varchar",32));
        salaryBillAddDTO.setEmpName(getRandomValue("varchar",32));
        salaryBillAddDTO.setWechatStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillAddDTO.setEmpNo(getRandomValue("varchar",32));
        salaryBillAddDTO.setDepId(getRandomValue("varchar",32));
        salaryBillAddDTO.setDepName(getRandomValue("varchar",255));
        salaryBillAddDTO.setPositionId(getRandomValue("varchar",32));
        salaryBillAddDTO.setPositionName(getRandomValue("varchar",255));
        salaryBillAddDTO.setDeduction(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryBillAddDTO.setSalaryBasic(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryBillAddDTO.setEmpSoc(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryBillAddDTO.setEmpPf(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryBillAddDTO.setEmpTax(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        salaryBillAddDTO.setCompanyId(getRandomValue("varchar",32));
        salaryBillAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",11)));
        return salaryBillAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryBillUpdateDTO
     */
    public SalaryBillUpdateDTO getSalaryBillUpdateDTO(SalaryBillVO salaryBillVO){
        return salaryBillService.selectDOById(salaryBillVO.getId(), SITE_ID).to(SalaryBillUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryBillQuery
     */
    public SalaryBillQuery getSalaryBillQuery() {
        SalaryBillQuery salaryBillQuery = new SalaryBillQuery();
        List<SalaryBillDO> salaryBillDOList = salaryBillService.list(new SalaryBillDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryBillDOList)) {
            SalaryBillDO salaryBillDO = salaryBillDOList.get(0);
            salaryBillQuery = salaryBillDO.to(SalaryBillQuery.class);
        }
        return salaryBillQuery;
    }

    /**
     * 保存示例
     * @return SalaryBillVO
     */
    public SalaryBillVO saveSalaryBillExample(){
        SalaryBillAddDTO addDTO = this.getSalaryBillAddDTO();
        SalaryBillVO salaryBillVO = salaryBillService.save(addDTO,buildTokenUser());
        AttendanceMonthlyAddDTO attendanceMonthlyAddDTO = new AttendanceMonthlyAddDTO();
        attendanceMonthlyAddDTO.setEmpId(salaryBillVO.getEmpId());
        attendanceMonthlyAddDTO.setYear(salaryBillVO.getYear());
        attendanceMonthlyAddDTO.setMonth(salaryBillVO.getMonth());
        attendanceMonthlyService.save(attendanceMonthlyAddDTO, buildTokenUser());
        return salaryBillVO;
    }


}

